package com.ssm.util;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * mybatis工具类
 * 
 * @author Administrator
 *
 */
public class MybatisUtil {

	private static SqlSessionFactory factory;
	// 只加载一次
	static {
		try {
			factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("configuration.xml"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 创建SqlSession
	public static SqlSession openSession() {
		//自动提交事物true
		return factory.openSession(true);
	}
}
